package com.lbj.googleplay.googleplay100.ui.holder;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;

import com.lbj.googleplay.googleplay100.R;
import com.lbj.googleplay.googleplay100.domain.AppInfo;
import com.lbj.googleplay.googleplay100.http.HttpHelper;
import com.lbj.googleplay.googleplay100.utils.UIUtils;

import org.xutils.ImageManager;
import org.xutils.x;

import java.util.ArrayList;

public class DetailPicsHolder extends BaseHolder<AppInfo>{

    private ImageView[] ivPics;
    private ImageManager imageManager;

    @Override
    public View initView() {
        View view = UIUtils.inflate(R.layout.layout_detail_picinfo);
        ivPics = new ImageView[5];
        ivPics[0] = view.findViewById(R.id.iv_pic1);
        ivPics[1] = view.findViewById(R.id.iv_pic2);
        ivPics[2] = view.findViewById(R.id.iv_pic3);
        ivPics[3] = view.findViewById(R.id.iv_pic4);
        ivPics[4] = view.findViewById(R.id.iv_pic5);
        imageManager = x.image();
        return view;
    }

    @Override
    public void refreshView(AppInfo data) {
        final ArrayList<String> screen = data.screen;
        for (int i = 0; i < 5; i++) {
            if (i<screen.size()){
                //设置图片
                String picUrl = screen.get(i);
                imageManager.bind(ivPics[i], HttpHelper.URL+"image?name="+picUrl);
                final int finalI = i;
                ivPics[i].setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent();
                        intent.putExtra("index", finalI);
                        intent.putExtra("screen",screen);
                        UIUtils.getContext().startActivity(intent);
                    }
                });
            }else {
                //隐藏没有数据的ImageView
                ivPics[i].setVisibility(View.GONE);
            }
        }
    }
}
